package com.hhit.zhgd.controller

import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.hhit.zhgd.domain.entity.ErrorLog
import com.hhit.zhgd.domain.entity.OperateLog
import com.hhit.zhgd.domain.response.BaseResp
import com.hhit.zhgd.service.ErrorLogService
import com.hhit.zhgd.service.LoginLogService
import com.hhit.zhgd.service.OperateLogService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
class LogController {
    @Autowired
    private val errorLogService: ErrorLogService? = null

    @Autowired
    private val loginLogService: LoginLogService? = null

    @Autowired
    private val operateLogService: OperateLogService? = null


    @GetMapping("/login/logs")
    fun getLoginLogList(
        username: String?,
        start: String?,
        end: String?,
        @RequestParam(name = "page", defaultValue = "1") page: Long,
        @RequestParam(name = "size", defaultValue = "15") size: Long
    ): BaseResp<Page<HashMap<String, Any?>>?> {
        val params = HashMap<String, Any?>().also {
            it["username"] = username
            it["start"] = start
            it["end"] = end
            it["page"] = page
            it["size"] = size
        }
        val list = loginLogService?.getList(params)
        return BaseResp.success(list)
    }


    @GetMapping("/error/logs")
    fun getErrorLogList(
        start: String?,
        end: String?,
        @RequestParam(name = "page", defaultValue = "1") page: Long,
        @RequestParam(name = "size", defaultValue = "15") size: Long
    ): BaseResp<Page<HashMap<String, Any?>>?> {
        val params = HashMap<String, Any?>().also {
            it["start"] = start
            it["end"] = end
        }
        val page = Page<ErrorLog>(page, size)
        val list = errorLogService?.getList(page, params)

        return BaseResp.success(list)
    }


    @GetMapping("/operate/logs")
    fun getOperateLogList(
        start: String?,
        end: String?,
        username:String?,
        @RequestParam(name = "page", defaultValue = "1") page: Long,
        @RequestParam(name = "size", defaultValue ="15") size:Long
    ):BaseResp<Page<HashMap<String,Any?>>?> {
        val params = hashMapOf<String,Any?>().also {
            it["start"]=start
            it["end"]=end
            it["username"]=username
        }
        val page = Page<OperateLog>(page,size)
        val list = operateLogService?.getList(page,params)
        return BaseResp.success(list)
    }
}






















